// 图解地址 https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/solution/mai-mai-gu-piao-de-zui-jia-shi-ji-ii-by-leetcode-s/


/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
    if (prices.length < 2) return 0
    var num = 0
    for (let i = 1; i < prices.length; i++) {
        let n = prices[i] - prices[i - 1]
        if (n > 0) num += n
    }
    return num
};

var attr = [1,2,3,4,5]
var rs = maxProfit(attr)
console.log(rs)